
package com.bangcommunity.bbframe.dynconfig.parser;

import com.bangcommunity.bbframe.common.utils.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Properties;

/**
 * Created by tanghc
 */
public abstract class ConfigValueParser<V> {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    public V parse(Properties properties, String key, V defaultValue) {
        if (null != properties) {
            Object o = properties.get(key);
            if (null != o) {
                String v = o.toString();
                if (StringUtils.isNotBlank(v)) {
                    return doParse(v);
                }
            }
        }
        return defaultValue;
    }

    public abstract V doParse(String v);
}
